﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace neside2.default_panel
{
    /// <summary>
    /// Default_Output.xaml 的交互逻辑
    /// </summary>
    public partial class Default_Output : UserControl
    {
        public Default_Output()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Plugin_Default._IDE.GetPipeline("output").Care(onRecv, onRecvBin);
        }
        private void onRecv(string tag, string value)
        {
            if (tag == "msg" || tag == "warn" || tag == "error")
            {
                this.Dispatcher.Invoke(() =>
                {
                    if (tag == "msg")
                    {
                        outputbox.Items.Add(value);
                    }
                    else if (tag == "warn")
                    {
                        TextBlock block = new TextBlock();
                        block.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));
                        block.Text = value;
                        outputbox.Items.Add(block);
                    }
                    else if (tag == "error")
                    {
                        TextBlock block = new TextBlock();
                        block.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
                        block.Text = value;
                        outputbox.Items.Add(block);
                    }
                });
            }

        }
        private void onRecvBin(string tag, byte[] data)
        {
            string txt = "[";
            for(var i=0;i<data.Length;i++)
            {
                txt += data[i].ToString("X02");
            }
            txt += "]";
            onRecv(tag, txt);
        }
    }
}
